package featuresdemo;

class TestClass{
	int count = 0;
	String name;
	TestClass(int count, String name){
		this.count = count;
		this.name = name;
	}
	
	//rewrite equals method
	public boolean equals(TestClass tc){
		return this.count == tc.count;
	}	
	
	public String toString() {
		return "my  count= "+this.count;  
	}
}

class ObjEqualsTest{
	public static void main(String []args){
		TestClass tc1 = new TestClass(1, "Allen");  
		TestClass tc2 = new TestClass(1, "Allen");
		
		if(tc1.equals(tc2))   
		    System.out.println("two obj are EQUAL");
		else
			System.out.println("two obj are NOT EQUAL");
        System.out.println(tc1.toString());  
        System.out.println(tc2);  
        
        //test normal String
        String t1 = "abc";
        String t2 = "abc";
	    System.out.println("not using new: == " + (t1 == t2));
	    System.out.println("not using new equals: " + (t1.equals(t2)));
        
        String new1 = new String("abc");
        String new2 = new String("abc");
	    System.out.println("using new: == " + (new1 == new2));
	    System.out.println("using new equals: " + (new1.equals(new2)));
	    
	    //obj
	    System.out.println("obj int field: == " + (tc1.name == tc2.name));
		System.out.println("obj String field ==: " + (tc1.name == tc2.name));
	    System.out.println("obj String field equals: " + (tc1.name.equals(tc2.name)));

		//
        String leftA = "abc";
        String leftB = new String("abc");
        System.out.println(leftA.equals(leftB));
        System.out.println(leftA == leftB);
        System.out.println(leftA.hashCode() + ":" + leftB.hashCode());
	}
}
